home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 19 / Mac Magazin and MacEasy Magazine CD - Issue 19.iso / Wissenschaft & Technik / WASTE 1.2a5 Distribution / WASTE 1.2a5 / WESelectors.c < prev    next >
Text File  |  1996-01-15  |  5KB  |  167 lines

  1. /*
  2.  *    WESelectors.c
  3.  *
  4.  *    WASTE PROJECT
  5.  *  Routines for manipulating selector lookup tables
  6.  *
  7.  *  Copyright (c) 1993-1996 Marco Piovanelli
  8.  *    All Rights Reserved
  9.  *
  10.  *  C port by Dan Crevier
  11.  *
  12.  */
  13.  
  14.  
  15. #include "WASTEIntf.h"
  16.  
  17. // MPW can't handle FIELD_DESC stuff (duh!)
  18.  
  19. #ifdef applec
  20.  
  21. // this is **ugly** and will break if we change the declaration of WERec
  22.  
  23. static WELookupTable _weMainSelectorTable[] = {
  24. { weRefCon,             0x0074, 0x0004 },
  25. { wePort,                0x0000, 0x0004 },
  26. { weText,                0x0004, 0x0004 },
  27. { weCharToPixelHook,    0x00B0, 0x0004 },
  28. { weCharByteHook,        0x00BC, 0x0004 },
  29. { weCharTypeHook,        0x00C0, 0x0004 },
  30. { weClickLoop,            0x0094, 0x0004 },
  31. { weCurrentDrag,        0x0084, 0x0004 },
  32. { weDrawTextHook,        0x00A8, 0x0004 },
  33. { weLineBreakHook,        0x00B4, 0x0004 },
  34. { weLineArray,            0x0008, 0x0004 },
  35. { wePixelToCharHook,    0x00AC, 0x0004 },
  36. { weTSMPostUpdate,        0x00A0, 0x0004 },
  37. { weTSMPreUpdate,        0x009C, 0x0004 },
  38. { weRunArray,            0x0010, 0x0004 },
  39. { weScrollProc,            0x0098, 0x0004 },
  40. { weStyleTable,            0x000C, 0x0004 },
  41. { weTSMDocumentID,        0x0078, 0x0004 },
  42. { weWordBreakHook,        0x00B8, 0x0004 },
  43. { weTranslateDragHook,    0x00A4, 0x0004 },
  44. #if WASTE_IC_SUPPORT
  45. { weURLHint,            0x00D8, 0x0004 },
  46. #endif
  47. { 0,                     0, 0 }};
  48.  
  49. #if WASTE_OBJECTS
  50.  
  51. static WELookupTable _weObjectHandlerSelectorTable[] = {
  52. { weClickHandler,        0x0010, 0x0004 },
  53. { weDrawHandler,        0x000C, 0x0004 },
  54. { weDisposeHandler,        0x0008, 0x0004 },
  55. { weNewHandler,            0x0004, 0x0004 },
  56. { weStreamHandler,      0x0014, 0x0004 },
  57. { 0,                     0, 0 }};
  58.  
  59. #endif  // WASTE_OBJECTS
  60.  
  61. #else
  62.  
  63. // proper way of defining selector tables
  64.  
  65. #define FIELD_OFFSET(FIELD, STRUCT)        (short) &((STRUCT *) 0L)->FIELD
  66. #define FIELD_SIZE(FIELD, STRUCT)        (short) sizeof(((STRUCT *) 0L)->FIELD)
  67. #define FIELD_DESC(FIELD, STRUCT)        { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
  68.  
  69. static WELookupTable _weMainSelectorTable[] = {
  70. { weRefCon,             FIELD_DESC(refCon,            WERec) },
  71. { wePort,                FIELD_DESC(port,              WERec) },
  72. { weText,                FIELD_DESC(hText,             WERec) },
  73. { weCharToPixelHook,    FIELD_DESC(charToPixelHook,   WERec) },
  74. { weCharByteHook,        FIELD_DESC(charByteHook,      WERec) },
  75. { weCharTypeHook,        FIELD_DESC(charTypeHook,      WERec) },
  76. { weClickLoop,            FIELD_DESC(clickLoop,         WERec) },
  77. { weCurrentDrag,        FIELD_DESC(currentDrag,       WERec) },
  78. { weDrawTextHook,        FIELD_DESC(drawTextHook,      WERec) },
  79. { weLineBreakHook,        FIELD_DESC(lineBreakHook,     WERec) },
  80. { weLineArray,            FIELD_DESC(hLines,            WERec) },
  81. { wePixelToCharHook,    FIELD_DESC(pixelToCharHook,   WERec) },
  82. { weTSMPostUpdate,        FIELD_DESC(tsmPostUpdate,     WERec) },
  83. { weTSMPreUpdate,        FIELD_DESC(tsmPreUpdate,      WERec) },
  84. { weRunArray,            FIELD_DESC(hRuns,             WERec) },
  85. { weScrollProc,            FIELD_DESC(scrollProc,        WERec) },
  86. { weStyleTable,            FIELD_DESC(hStyles,           WERec) },
  87. { weTSMDocumentID,        FIELD_DESC(tsmReference,      WERec) },
  88. { weWordBreakHook,        FIELD_DESC(wordBreakHook,     WERec) },
  89. { weTranslateDragHook,    FIELD_DESC(translateDragHook, WERec) },
  90. #if WASTE_IC_SUPPORT
  91. { weURLHint,            FIELD_DESC(hURLHint,          WERec) },
  92. #endif
  93. { 0,                     0, 0 }};
  94.  
  95. #if WASTE_OBJECTS
  96.  
  97. static WELookupTable _weObjectHandlerSelectorTable[] = {
  98. { weClickHandler,        FIELD_DESC(clickHandler,      WEOHTableElement) },
  99. { weDrawHandler,        FIELD_DESC(drawHandler,       WEOHTableElement) },
  100. { weDisposeHandler,        FIELD_DESC(freeHandler,       WEOHTableElement) },
  101. { weNewHandler,            FIELD_DESC(newHandler,        WEOHTableElement) },
  102. { weStreamHandler,      FIELD_DESC(streamHandler,     WEOHTableElement) },
  103. { 0,                     0, 0 }};
  104.  
  105. #endif    // WASTE_OBJECTS
  106.  
  107. #endif    // !applec
  108.  
  109. pascal void _WELookupSelector(const WELookupTable *table, WESelector selector, WEFieldDescriptor *desc)
  110. {
  111.     for ( ; table->selector != selector ; table++ )
  112.         if ( * (long *) &(table->desc) == 0L )
  113.             break;
  114.     
  115.     *desc = table->desc;
  116. }
  117.  
  118. pascal OSErr _WEGetField(const WELookupTable *table, WESelector selector, long *info, void *structure)
  119. {
  120.     WEFieldDescriptor desc;
  121.     
  122.     _WELookupSelector(table, selector, &desc);
  123.     
  124.     if (desc.fLength == 0)
  125.         return weUndefinedSelectorErr;
  126.     
  127.     *info = * (long *) ((long) structure + desc.fOffset);
  128.     return noErr;
  129. }
  130.  
  131. pascal OSErr _WESetField(const WELookupTable *table, WESelector selector, long *info, void *structure)
  132. {
  133.     WEFieldDescriptor desc;
  134.     
  135.     _WELookupSelector(table, selector, &desc);
  136.     
  137.     if (desc.fLength == 0)
  138.         return weUndefinedSelectorErr;
  139.     
  140.     * (long *) ((long) structure + desc.fOffset) = *info;
  141.     return noErr;
  142. }
  143.  
  144. pascal OSErr WEGetInfo(WESelector selector, void *info, WEHandle hWE)
  145. {
  146.     return _WEGetField(_weMainSelectorTable, selector, (long *)info, (void *)*hWE);
  147. } // WEGetInfo
  148.  
  149. pascal OSErr WESetInfo(WESelector selector, const void *info, WEHandle hWE)
  150. {
  151.     OSErr err;
  152.     
  153.     err = _WESetField(_weMainSelectorTable, selector, (long *)info, (void *)*hWE);
  154.     
  155.     // the hook fields can never be NULL, so replace any NULL field with the default address
  156.     _WESetStandardHooks(hWE);
  157.     
  158.     return err;
  159. } // WESetInfo
  160.  
  161. #if WASTE_OBJECTS
  162. // for some reason _WESetField doesn't work from other files (?)
  163. pascal OSErr _WESetHandler(WESelector selector, long *info, void *structure)
  164. {
  165.     return _WESetField(_weObjectHandlerSelectorTable, selector, info, structure);
  166. }
  167. #endif